/*
	FileName : app_led.c
	Description : 
	
	Created on 2013.10.27 by ZZP.
	
	Revision History:
	
*/

#include "bsp.h"
#include "app.h"
#include "app_led.h"


uint16_t	STMLedTm;
uint16_t	CANLedTm;
uint16_t	TaxLedTm;
	
void STM_Led(void);
void CAN_Led(void);
void COM_Led(void);

/////////////////////////////////////////////////////////////////////////////////
///							Global Function realizations
/////////////////////////////////////////////////////////////////////////////////
void AppTaskLED(void *p_arg)
{
	(void)p_arg;

	while (DEF_TRUE){
		
		if (AppInfo.RdyFlag){
			
			STM_Led();
			CAN_Led();
			COM_Led();
		}
		
		AppInfo.TaskLedCnt++;
		
		OSTimeDly(10);
	}
}

/////////////////////////////////////////////////////////////////////////////////
///							Local Function realizations
/////////////////////////////////////////////////////////////////////////////////

void STM_Led(void)
{
	if (AppInfo.UartLedFlag){
		
		if (STMLedTm >= 3){
			
			BSP_LED_Off(LED_BTM);
			STMLedTm = 0;
			AppInfo.UartLedFlag--;
		}
		else if (STMLedTm > 1)
			BSP_LED_Off(LED_BTM);
		else
			BSP_LED_On(LED_BTM);
		
		STMLedTm++;
	}
	else
		STMLedTm = 0;
}

void CAN_Led(void)
{
	if (AppInfo.CanLedFlag){
		
		if (CANLedTm >= 3){
			
			CANLedTm = 0;
			AppInfo.CanLedFlag--;
		}
		else if (CANLedTm > 1)
			BSP_LED_Off(LED_CAN);
		else
			BSP_LED_On(LED_CAN);
		
		CANLedTm++;
	}
	else
		CANLedTm = 0;
}

void COM_Led(void)
{
	if(AppInfo.TaxValidtype == 0)
	{
		BSP_LED_On(LED_COM);
		return;
	}

	if (TaxLedTm >= 100){
			TaxLedTm = 0;
	}
	else if (TaxLedTm > 12)
		BSP_LED_Off(LED_COM);
	else
		BSP_LED_On(LED_COM);
	
	TaxLedTm++;
	
}











